/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.view.tabs.results.background;

import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author jmj
 */
public class BackgroundTableModel extends AbstractTableModel {

    private List data;
    private String[] columnNames = {"Incluir", "Descripción"};
    public final static int INDEX_SELECT = 0;
    public final static int INDEX_DESCRIPTION = 1;
    private Boolean[] selected;

    /**
     * 
     * @param data
     */
    public BackgroundTableModel(List data){
        super();
        this.data = data;
        this.selected = new Boolean[data.size()];
        int i =0;
        while (i<data.size()){
            this.selected[i] = Boolean.FALSE;
            i++;
        }
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case BackgroundTableModel.INDEX_DESCRIPTION:
                return Object.class;
            case BackgroundTableModel.INDEX_SELECT:
                return Boolean.class;
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int column) {
        return this.columnNames[column];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return (columnIndex == BackgroundTableModel.INDEX_SELECT);
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case BackgroundTableModel.INDEX_DESCRIPTION:
                this.data.set(rowIndex, aValue);
                break;
            case BackgroundTableModel.INDEX_SELECT:
                this.selected[rowIndex] = (Boolean) aValue;
                this.fireTableDataChanged();
                break;
        }
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case BackgroundTableModel.INDEX_DESCRIPTION:
               return this.data.get(rowIndex);

            case BackgroundTableModel.INDEX_SELECT:
                return this.selected[rowIndex] ;
        }
        return null;
    }

    
}
